package com.gzhuxj201.controller;

import com.gzhuxj201.entity.PageBean;
import com.gzhuxj201.entity.Result;
import com.gzhuxj201.entity.Teacher;
import com.gzhuxj201.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/teachers")
@Slf4j
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping
    public Result selectByPage(int page, int pageSize,String tno, String username, Short gender){
        log.info(page+"-"+pageSize);
        log.info(username+"-"+gender);
        PageBean pageBean = teacherService.page(page, pageSize,tno,username, gender);
        return Result.success(pageBean);
    }

    @PostMapping
    public Result add(@RequestBody Teacher teacher){
        teacherService.add(teacher);
        return Result.success();
    }

    @GetMapping("{tno}")
    public Result selectById(@PathVariable Integer tno){
        Teacher teacher= teacherService.selectById(tno);
        return Result.success(teacher);
    }

    @PutMapping()
    public Result update(@RequestBody Teacher teacher){
        teacherService.update(teacher);
        return Result.success();
    }

    @DeleteMapping("{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        int res= teacherService.deleteByIds(ids);
        return Result.success();
    }



}
